package cn.lijiajia3515.cairo.system.modules.file;


import cn.lijiajia3515.cairo.mongo.data.AbstractMongo;
import cn.lijiajia3515.cairo.mongo.data.MetaMongo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.MongoId;

import java.time.LocalDateTime;

@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)

@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder(toBuilder = true)
public class FileMongo extends AbstractMongo {

	/**
	 * id
	 */
	@MongoId
	private ObjectId _id;

	/**
	 * client
	 */
	private String client;

	/**
	 * folder path
	 */
	private String path;

	/**
	 * filename
	 */
	@org.springframework.data.mongodb.core.mapping.Field("filename")
	private String filename;

	/**
	 * 文件大小
	 */
	@org.springframework.data.mongodb.core.mapping.Field("length")
	private Long length;

	/**
	 * chunk Size
	 */
	@org.springframework.data.mongodb.core.mapping.Field("chunkSize")
	private Integer chunkSize;

	/**
	 * 文件时间
	 */
	@org.springframework.data.mongodb.core.mapping.Field("uploadDate")
	private LocalDateTime uploadDate;

	/**
	 * md5
	 */
	@org.springframework.data.mongodb.core.mapping.Field("md5")
	private String md5;

	/**
	 * Metadata
	 */
	@Builder.Default
	@org.springframework.data.mongodb.core.mapping.Field("metadata")
	private FileMongo.meta meta = new meta();

	public static final Field FIELD = new Field();

	@Data
	@EqualsAndHashCode(callSuper = true)
	@ToString(callSuper = true)

	@NoArgsConstructor
	public static class meta extends MetaMongo {
		/**
		 * 文件类型
		 */
		@org.springframework.data.mongodb.core.mapping.Field("_contentType")
		private String _contentType;
	}

	public static class Field extends AbstractMongo.Field {
		public final String CLIENT = field("client");
		public final String PATH = field("path");
		public final String FILENAME = field("filename");
		public final String LENGTH = field("length");
		public final String CHUCK_SIZE = field("chuckSize");
		public final String UPLOAD_DATE = field("uploadDate");
		public final String MD5 = "md5";

		public static class Meta extends AbstractMongo.Field {
			public Meta() {
			}

			public Meta(AbstractMongo.Field parent, String prefix) {
				super(parent, prefix);
			}

			public static final String _CONTENT_TYPE = "_contentType";
		}
	}

}
